package BehavioralPattern.Command;


/**
 * @Classname : Command
 * @Description : 命令角色
 * @Author : chentianyu
 * @Date 2023/3/7 07:29
 */

// 抽象命令
public abstract class Command {

    protected final Receiver receiver;

    public Command(Receiver receiver) {
        this.receiver = receiver;
    }

    // 命令执行入口
    public abstract void execute();

}


// 具体命令——建造合同提交审批
class ConstructionContractSubmit extends Command {

    public ConstructionContractSubmit() {
        // 一般具体命令类名可以指定具体接受者，可以在命令类中直接封装接受者，解除高层模块对接受者的依赖
        super(new ConstructionContract());
    }

    @Override
    public void execute() {
        super.receiver.submit();
    }
}


// 具体命令——建造合同撤回审批
// 该命令相当于"建造合同提交审批"命令的逆向命令
// 另一种实现撤回的方式时通过备忘录模式记录原始状态然后恢复原始状态
class ConstructionContractRecall extends Command {

    public ConstructionContractRecall() {
        super(new ConstructionContract());
    }

    @Override
    public void execute() {
        super.receiver.recall();
    }
}


// 具体命令——营销合同提交审批
class MarketingContractSubmit extends Command {

    public MarketingContractSubmit() {
        super(new MarketingContract());
    }

    @Override
    public void execute() {
        super.receiver.submit();
    }
}
